let express = require("express")();
let mysql = require("mysql");
let expressStatic = require("express-static");


var sql = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'chuanyue'
});

sql.connect();
express.get("/list", (request, response) => {
    sql.query(`SELECT id,img,tittle,subhead FROM news`, (error, data) => {
        response.send(data)
    })
})
express.get("/count", (request, response) => {
    let id = request.query.id
    sql.query(`SELECT * FROM news WHERE id="${id}"`, (error, data) => {
        if (error) {
            response.send("error")
            console.log(error)
        } else {
            response.send(data[0])
        }
    })
})
express.use(expressStatic(__dirname + '/news'));
express.listen(81)